﻿// -----------------------------------------------------------------------
// <copyright file="ByteArraysCombineExtension.cs" company="Softserve">
// Опрацьовую вхідну інформацію і парсить її
// </copyright>
// -----------------------------------------------------------------------
namespace WebServer.BusinessLogic.Helpers
{
    using System.Linq;

    /// <summary>
    /// Class ByteArraysCombineExtension
    /// </summary>
    public static class ByteArraysCombineExtension
    {
        /// <summary>
        /// Combining byte array
        /// </summary>
        /// <param name="arrays">array of bytes</param>
        /// <returns>byte array after combining</returns>
        public static byte[] Combine(params byte[][] arrays)
        {
            byte[] rv = new byte[arrays.Sum(a => a.Length)];
            int offset = 0;
            foreach (byte[] array in arrays)
            {
                System.Buffer.BlockCopy(array, 0, rv, offset, array.Length);
                offset += array.Length;
            }

            return rv;
        }
    }
}
